﻿/*----------------------------------------------------------------------------------------
*
*  Copyright 2019, Gao Hai Hui, <fromzeropoint@126.com>.  All rights reserved.
*  https://gitee.com/helloworldghh/xoskit.git
*  Use of this source code is governed by a MIT license
*  that can be found in the License file.
*
----------------------------------------------------------------------------------------*/
#ifndef __XOSKIT_XOS_CORE_XOS_STL_SRC_PROTOCOL_PUBLIC_PACKAGE_H__
#define __XOSKIT_XOS_CORE_XOS_STL_SRC_PROTOCOL_PUBLIC_PACKAGE_H__

#include "../base/head.h"

namespace xos_protocol
{

	class public_package : public base
	{
    public:
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        // 
        typedef base BASE;

	public:
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        // 
		public_package( xos_box::i_serial * pSerial, xos_box::i_buf * pBuf ) : 
            BASE( pSerial, pBuf )
        {
        }
		~public_package()
        {
        }

	public:
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        // 
		int req_compose( int nCookie, int nCmd )
		{
			xos::xos_u32 uCookie = nCookie;
			xos::xos_u8 uCmd = nCmd;
			int ret = 0;
			if( 0 == ret )
			{
				ret = pack_int32( uCookie );
			}
			if( 0 == ret )
			{
				ret = pack_int8( uCmd );
			}
			return ret;
		}
		int req_dis_compose( int & nCookie, int & nCmd )
		{
			xos::xos_u32 uCookie = 0;
			xos::xos_u8 uCmd = 0;
			int ret = 0;
			if( 0 == ret )
			{
				ret = un_pack_int32( &uCookie );
			}
			if( 0 == ret )
			{
				ret = un_pack_int8( &uCmd );
			}
			if( 0 == ret )
			{
				nCookie = uCookie;
				nCmd = uCmd;
			}
			return ret;
		}
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        // 
		int res_compose( int nCookie, int nCmd )
		{
			xos::xos_u32 uCookie = nCookie;
			xos::xos_u8 uCmd = nCmd;
			int ret = 0;
			if( 0 == ret )
			{
				ret = pack_int32( uCookie );
			}
			if( 0 == ret )
			{
				ret = pack_int8( uCmd );
			}
			return ret;
		}
		int res_dis_compose( int & nCookie, int & nCmd )
		{
			xos::xos_u32 uCookie = 0;
			xos::xos_u8 uCmd = 0;
			int ret = 0;
			if( 0 == ret )
			{
				ret = un_pack_int32( &uCookie );
			}
			if( 0 == ret )
			{
				ret = un_pack_int8( &uCmd );
			}
			if( 0 == ret )
			{
				nCookie = uCookie;
				nCmd = uCmd;
			}
			return ret;
		} 
	};

}

#endif // __XOSKIT_XOS_CORE_XOS_STL_SRC_PROTOCOL_PUBLIC_PACKAGE_H__
